<style type="text/css">
    .belongToLi
    {
    	display: inline;
    	list-style-type: none;
    	padding-right: 20px; 
    }
</style>
<script src="/public/library/hvn/place.js" type="text/javascript"></script>
<script src="/public/library/hvn/autocomplete.tour.js" type="text/javascript"></script>
<script src="/public/library/autocomplete/autocomplete.js" type="text/javascript"></script>
<link rel="stylesheet" href="/public/library/autocomplete/autocomplete.css" type="text/css">
<link rel="stylesheet" href="/public/themes/second/css/navigationTab.css" type="text/css">
<script language="Javascript">
$(function(){
	if($("select#departure_city_id").val() != 0)
		$('.district').show();
	else
		$('.district').hide();
	$("select#departure_city_id").change(function()
		{   
			$.getJSON("/en/place/Ajax/get-district",
				{
					city_id: $(this).val(), 
					ajax: 'true'
				}, 
                function(json){    
                    var options = '';
                    for (var i = 0; i < json.length; i++) {
                           options += '<option value="' + json[i].id + '">' + json[i].name + '</option>';
                    }
                    if($("select#departure_city_id").val() == 0)
                    {
                    	$("select#departure_district_id option").removeAttr("selected");
                    	$('.district').hide();
                    }
                    else
                    {
                    	$('.district').show();
                    }
                   	$("select#departure_district_id").html(options);
             })
     });
     
	
	$("form").submit(function(){
		var tmp = '';
		var ids = '';
		var dis = '';
		$("#belong_to_names ul li").each(function(i){
			//get ids: $(this).attr('name')
			//get name, ids and distance
			if (tmp == '' && ids == '')
			{
				tmp = $(this).find("span:first").text();
				ids = $(this).attr('name');
				dis = $(this).find("span:last").text();
			}
			else
			{
				tmp = tmp + ',' + $(this).find("span:first").text();
				ids = ids + ',' + $(this).attr('name');
				dis = dis + ',' + $(this).find("span:last").text();
			}
		});
		$("#belong_to_ids").val(ids);
		$("#belong_to_names_submit").val(tmp);
		$("#distance").val(dis);
	});
	
	var mode = '';
    getAddress(mode); //function in place.js
    getCategoryType(mode);
	
	setAutoComplete("belong_to_ac_input", "belong_to_ids", "belong_to_names", "results", "/en/place/ajax/autocomplete?part=");
	
	$('.editPlaceArrival').openDOMWindow({ 
			height:300, 
			width:400, 
			eventType:'click',
			overlay:0, 
			windowBGColor:'#FFFF00', 
			borderColor:'#5D5DF4', 
			overlayOpacity:15
	}); 
	$('.closePlaceDOMWindow').closeDOMWindow({eventType:'click'}); 
	
	/* Arrival Address*/
	$('.showAddressArrival').click(function(){
		$(".arrivalCity").toggle();
		return false;
	});
	$("#current-legs").trigger('click');
	
});
</script>

<div class="errorMessage"> 
	<?if(isset($this->viewParams['errorMessage'])):?>
		<?=$this->viewParams['errorMessage'] ?> 
	<?endif?>
	</div>
<div class="successMessage"> 
	<?if(isset($this->viewParams['successMessage'])) :?><?=$this->viewParams['successMessage'] ?> <?endif?>
</div>
	<ul  class="navigationTab">
<?if(isset($this->viewParams['mode']) && $this->viewParams['mode'] == 'edit-tleg') :?>
		<li> <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'edit'))?>?id=<?=$this->viewParams['tid']?>"> Edit Tour </a> </li>
		<li class="selected"> <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'edit-tleg'))?>?id=<?=$this->viewParams['tid']?>"> Edit Tleg </a> </li>
		<li > <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'gallery'))?>?id=<?=$this->viewParams['tid']?>"> <?=t(6)?> </a> </li>
		<li > <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'list-tleg'))?>?id=<?=$this->viewParams['tid']?>">List Tleg</a> </li>
		<li> <a target="_blank" href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'view'))?>?id=<?=$this->viewParams['tid']?>"> <?=t(134)?> </a> </li>
<?else:?>
		<li> <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'edit'))?>?id=<?=$this->viewParams['tid']?>"> Edit Tour </a> </li>
		<li class="selected"> <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'new-tleg'))?>?tid=<?=$this->viewParams['tid']?>&leg_number=<?=$this->viewParams['leg_number']?>"> New Tleg </a> </li>
		<li > <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'gallery'))?>?id=<?=$this->viewParams['tid']?>"> <?=t(6)?> </a> </li>
		<li > <a href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'list-tleg'))?>?id=<?=$this->viewParams['tid']?>">List Tleg</a> </li>
		<li> <a target="_blank" href="<?=$this->hvnUrl(array('module' => 'tour', 'action' => 'view'))?>?id=<?=$this->viewParams['tid']?>"> <?=t(134)?> </a> </li>
<?endif?>
	</ul>
	
<h3> <?=t(830) ?> 
<?if(isset($this->viewParams['tour'])):?><?=$this->viewParams['tour']['name'] ?><?endif?>(#<?=$this->viewParams['tid'] ?>)</h3>
<fieldset class="expansible"><legend id="current-legs"><span><?=t(831) ?></span></legend>
	<?$tour = $this->viewParams['tour']; ?>
	<?if (count ($tour['legs']) > 0) :?>
	<? foreach ($tour['legs'] as $leg_num => $leg) :?>
		<?$metadata = unserialize($leg['leg']['metadata']);?>
	    <div style="border:1px solid #d8d9d9;margin-left:20px"> # <?=$leg['leg']['leg_number']?> : <b> <?=$leg['leg']['tleg_name']?></b> 
	        <br/><?=t(17)?>:&nbsp;&nbsp; <?=$metadata['departure_place_name'] ?> --- <?=t(18) ?> <?=$metadata['arrival_place_name'] ?> 
	        <br/><br/>
	        <?=$leg['article']['article_body'] ?>
	        <div style="text-align:right;background:#eee"> <a href="<?= $this->hvnUrl(array('module'=>'tour', 'action'=>'edit-tleg')) . '?id=' . $leg['leg']['id'] . '&tid=' . $tour['id']?>">
	            <?=t(38) ?></a>
	        </div>
	    </div>
	<?endforeach ?>
	<?endif ?>
</fieldset>


<fieldset class="expansible"><legend>
<span> <?=t(842)?> #: <?if(isset($this->viewParams['leg_number'])) :?><?=$this->viewParams['leg_number']?><?endif?> 
</span></legend>
<div>
( Tour Language: (<?=$tour['lang']?>) )

<form id="newEvent" accept-charset="UTF-8" action="<?= $this->escape($this->viewParams['form']->getAction()) ?>"
      method="<?= $this->escape($this->viewParams['form']->getMethod()) ?>">
<br/>
<table>
<tr>
	<td width="120px"><?=t(843)?></td>
	<td> <?=$this->viewParams['form']->tleg_name?></td>
</tr>
<!-- 
<?=t(835) ?> (<b style="color:blue"><?=$this->departurePlaceName?> <?=('#'.$this->departurePlaceid)?></b>)
<br/>
-->
<tr>
	<td width="120px"><?=t(835)?></td>
	<td> <?=$this->viewParams['form']->departure_place_name?></td>
</tr>
<tr>
	<td width="120px"><?=t(792)?></td>
	<td> <?=$this->viewParams['form']->departure_city_id?>
		<span class="district"><?=t(771) ?>:<?= $this->viewParams['form']->departure_district_id?></span>
	
	</td>
</tr>

<tr>
	<td width="120px"><?=t(20)?></td>
	<td> 
	<input type="hidden" value="<?=$this->departure_place_id ? $this->departure_place_id : 0?>" name="departure_place_id"/>
	<?=$this->viewParams['form']->departure_date ?> <?=t(16) ?> :<?=$this->viewParams['form']->departure_time ?> (hour)  
	</td>
</tr>
<tr>
	<td width="120px"><?=t(836)?></td>
	<td> (<b style="color:blue"><?=$this->arrivalPlaceName?> <?=('#'.$this->arrivalPlaceid)?></b>)
			<a href="#inlinePlaceArrival" class="editPlaceArrival">Edit Place</a> | <a href="javascript:void()" class="showAddressArrival"> Edit Address</a>
			<br/> 
			
			<table class="arrivalCity" style="display:none;">
				<tr>
					<td><?=t(776) ?>:</td>
					<td><?=$this->viewParams['form']->arrival_place_name ?>
				</tr>
				<tr>
					<td><?=t(792) ?>:</td>
					<td><?= $this->viewParams['form']->city_id?></td>
				</tr>
				<tr id="district">
					<td ><?=t(771) ?>:</td>
					<td><?= $this->viewParams['form']->district_id?></td>
				</tr>
			</table>	
	</td>
</tr>
<tr>
		<td width="120px"><?=t(20) ?>
		<td> <?=$this->viewParams['form']->arrival_date ?>  <?=t(16) ?> :<?=$this->viewParams['form']->arrival_time?> (hour)
		</td>  

</tr>
<tr>
		<td width="120px"><?=t(819) ?>
		<td> <?=$this->viewParams['form']->duration ?> hours
		</td>  
</tr>

<tr>
		<td width="120px"><?=t(837) ?>
		<td> <?=$this->viewParams['form']->arrival_accommodation_type ?> 
		</td>  
</tr>

<tr>
		<td width="120px"><?=t(838) ?>
		<td> <?=$this->viewParams['form']->transport_type ?> <?=t(844) ?>: <?=$this->viewParams['form']->transport_company ?> 
		</td>  
</tr>
</table>
<div>
<h3><?=t(21) ?></h3>
	<?=$this->viewParams['form']->description?>

</div>

<div id="inlinePlaceArrival" style="display: none;">
	<table>
		<tr>
			<td><?=t(113) ?>:</td>
			<td><?= $this->viewParams['form']->category?></td>
		</tr>
		<tr>
			<td><?=t(115) ?>:</td>
			<td><?= $this->viewParams['form']->rtype?></td>
		</tr>
		<tr>
			<td><?=t(765) ?>:</td>
			<td><input type="text" id="belong_to_ac_input" name="belong_to_ac_input"/> <span id="newBelongToPlaceId"></span></td>
			<td> <div id="resultID"></div></td>
		</tr>
		<tr>	
			<td></td>
			<td><input type="text" id="length" />(km)</td>
		</tr>
		<tr>
			<td></td>
			<td><div align="right">
				<input type="button" value="Add" class="belongButton" />
				<input type="button" value="Close" class="closePlaceDOMWindow" />
				</div>
			</td>
		</tr>
	</table>
</div>
	<span id="belong_to_names"> <ul></ul></span>
	<input type="hidden" id="belong_to_ids" name="belong_to_ids" value="<?=$this->ids?>"/>
	<input type="hidden" id="belong_to_names_submit" name="belong_to_names_submit" value="<?=$this->name?>"/>
	<input type="hidden" id="distance" name="distance" value="<?=$this->dis?>"/>

<input type="hidden" value="<?=$this->viewParams['arrival_place_id'] ? $this->viewParams['arrival_place_id'] : 0 ?>" name="arrival_place_id"/>
<br/> 


<br/>
<?=t(839) ?>? <?=$this->viewParams['form']->is_last_leg?> 
<input type="hidden" value="<?=$this->viewParams['tid']?>" name="tid"/>
<input type="hidden" value="<?=$this->viewParams['leg_number']?>" name="leg_number"/>
<br/>
<br/>
<?=$this->viewParams['form']->submit ?>
</form>
</div>
</fieldset>